/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.smp.controler;

import br.gov.cemaden.library.model.smp.Swap;
import java.io.Serializable;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

/**
 *
 * @author Simone Santos
 */
public class SwapSistemaBean implements Serializable {

    Swap sa = new Swap();

    public SwapSistemaBean() {
    }

    public Swap getSwap() {
        Sigar sigar = new Sigar();

        try {
            //converte de long para MB e arredondar
            double swapU = Math.round(((sigar.getSwap().getUsed() / 1024.0) / 1024.0) * 100.0) / 100.0;
            double swapT = Math.round(((sigar.getSwap().getTotal() / 1024.0) / 1024.0) * 100.0) / 100.0;
            double swapF = Math.round(((sigar.getSwap().getFree() / 1024.0) / 1024.0) * 100.0) / 100.0;

            sa.setSwapUsed(swapU);
            sa.setSwapTotal(swapT);
            sa.setSwapFree(swapF);

        } catch (SigarException e) {
            System.out.println("Erro no SwapSistemaBean.setAllInformationSwap: " + e.getMessage() + " - " + e.getCause());
        }
        return sa;
    }

    public void show(Swap t) {
        System.out.println("SwapUsed: " + t.getSwapUsed() + " MB");
        System.out.println("SwapTotal: " + t.getSwapTotal() + " MB");
        System.out.println("SwapFree: " + t.getSwapFree() + " MB");
        System.out.println("--------------------------------\n");
    }
}
